<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
require_once( '../system/mdao/Class_M_OTHER.php' );
class Class_M_INS_SHOP extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table = "M_INS_SHOP";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey = "id";
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "ins_shop_cd";
	 
	 protected $_cols     = array(
	 	"ins_shop_cd"     => array(AOKI_VARTYPE_STR),
		"ins_shop_name"   => array(AOKI_VARTYPE_STR),
		"block_cd"        => array(AOKI_VARTYPE_STR),
		"block_name"      => array(AOKI_VARTYPE_STR),
		"local_cd"        => array(AOKI_VARTYPE_STR),
		"local_name"      => array(AOKI_VARTYPE_STR),
		"ins_co_cd"       => array(AOKI_VARTYPE_STR),
	    "ins_co_name"     => array(AOKI_VARTYPE_STR),
	    "media_cd"        => array(AOKI_VARTYPE_STR),
		"media_name"      => array(AOKI_VARTYPE_STR),
		"insert_conums"   => array(AOKI_VARTYPE_INT),
		"area_pattern_cd" => array(AOKI_VARTYPE_INT),
		"area_adnums"     => array(AOKI_VARTYPE_INT),
		"area_memo"       => array(AOKI_VARTYPE_STR),
		"delive_name"     => array(AOKI_VARTYPE_STR),		
		"shop_away"       => array(AOKI_VARTYPE_STR),
		"aoki_compete"    => array(AOKI_VARTYPE_STR),
		"home_percent"    => array(AOKI_VARTYPE_STR),
		"all_amount"      => array(AOKI_VARTYPE_STR),
		"sale_share"      => array(AOKI_VARTYPE_STR),
		"stop_date"       => array(AOKI_VARTYPE_STR),
	 );
	
	 protected $_checks  = array(
		"ins_shop_cd"     => array( "EXIST" ),
		"ins_shop_name"   => array( "EXIST" ),
		"block_cd"        => array( "EXIST" ),
		"local_cd"        => array( "EXIST" ),
		"ins_co_cd"       => array( "EXIST" ),
		"media_name"      => array( "EXIST" ),
		"delive_name"     => array( "EXIST" ),
		"insert_conums"   => array( "EXIST" ,"NUM" ),
		"area_pattern_cd" => array( "NUM" ),
		"area_adnums"     => array( "NUM" ),
		"home_percent"    => array( "NUM" ),
		"all_amount"      => array( "NUM" ),
		"sale_share"      => array( "NUM" ),
		"stop_date"       => array( "YMD" )
	 );
	 
	 //maxlength 
	 protected $_maxlens  = array(
		"ins_shop_cd"      =>  25 ,
		"ins_shop_name "   =>  100 ,
		"local_name"       =>  50 ,
		"ins_co_name"      =>  100 ,
		"media_name"       =>  100,
		"area_memo"        =>  300,
		"aoki_compete"     =>  20,
		"delive_name"      =>  100,
		"memo"             =>  1000,
	 );
	
	 public function search($where ,&$page = NULL ){
	 	$nowMatrix_cd = Class_M_OTHER::getNowMatrix_cd();
	 	
		$sql = "SELECT a.*,CASE WHEN a.stop_date <= CURDATE() + 0 and (a.stop_date > 0)     THEN '1'  ELSE '0' END AS disp_ng," .
				"(select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a " ;
				/*
				"left join (select aa.ins_shop_cd,group_concat(bb.shop_name  separator ',')  as shop " .
				" from M_INS_SHOP_SHOP{$nowMatrix_cd} aa " .
				" inner join M_SHOP  bb on aa.shop_cd = bb.shop_cd  " .
				" group by ins_shop_cd ) b on a.ins_shop_cd = b.ins_shop_cd  ";
				*/
				
			$sqlcnt =   "SELECT COUNT(*) AS cnt FROM M_INS_SHOP a";
		return  parent::search($where ,$page ,$sql,$sqlcnt);
	}
}

?>